<?php

session_start();

require_once('class/login_model.php');
include('config.php');

$user = $_POST['user'];
$pass = $_POST['pass'];

$login_model = new Login_model();
$res = $login_model->check_username($user, $pass);

if(mysql_num_rows($res) == 0){	
	$_SESSION['err_msg'] = 'Username dan password yang Anda masukkan salah!';
	header('Location: /incofarming/Views/login_view.php');
} else {
	$_SESSION['logged_in'] = true;
	while($row = mysql_fetch_array($res)){
		$id_user = $row['IDUSER'];
		$id_priv = $row['IDPRIVILEGE'];
		$_SESSION['id_user'] = $id_user;
		$_SESSION['id_priv'] = $id_priv;
		$nama_privilege = $row['NAMAPRIVILEGE'];
		if($nama_privilege == 'Admin Koperasi'){
			header('Location: /incofarming/Functions/koperasi/dashkop.php');
		} else {
			header('Location: /incofarming/Functions/admin/dashboard-admin.php');
		}
	}
	
	
	
}

?>